package com.shao.app.controller;

import com.shao.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author PaoFu
 */
@RestController
public class RefundController {

    @Autowired
    private UserService userService;

    /**
     * 用户申请退款接口
     * @param userId
     * @param request
     * @return
     */
    @PostMapping("/user/{userId}/refund")
    public Map<String, Object> applyRefund(@PathVariable Long userId, @RequestBody Map<String, Object> request) {
        Map<String, Object> response = new HashMap<>();
        double amount = (double) request.get("amount");
        userService.applyRefund(userId, amount);
        response.put("status", "success");
        return response;
    }
}
